<!Doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>注册</title>
    <link href="../css/register.css" rel="stylesheet" type="text/css">

    <script type="text/javascript" charset="utf-8" src="../js/base/jquery.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/base/base.js"></script>

    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon" rel="bookmark"/>
    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon" rel="icon"/>
    <link href="../image/base/favicon.ico" mce_href="../image/base/favicon.ico" type="image/x-icon"
          rel="shortcut icon"/>
</head>

<body>
<div id="header">
    <a href="../index.html" class="spark" target='_blank'></a>
</div>
<div id="container">
    <div class="register">
        <a href="loading.html" style="float:right">已有账号？直接登录</a>
    </div>
    <div class="register-box">
        <h2>使用手机注册您的账号</h2>
        <h3>此账号可在网站内使用</h3>

            <table>
                <tr>
                    <td style="width:145px;display:inline-block;vertical-align:middle">
                        <input id="telephone" placeholder="手机号码" style="width:115px;" oncut="return false;">
                    </td>
                    <td style="width:80px; display:inline-block;vertical-align:middle">
                        <input class="send-code-gray"  onclick="settime(this)" value="获取验证码" style="width:80px;">
                    </td>

                </tr>
                <tr>
                    <td><input id="code" class="code" maxlength="4" placeholder="验证码" oncut="return false;"></td>
                </tr>
                <tr>
                    <td>
                        <input type="password"  id="password" placeholder="请输入6~16位密码" oncut="return false;" maxlength="16">
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="password" id="password1" oncut="return false;" placeholder="请再次输入密码" maxlength="16">
                    </td>
                </tr>
                <tr>
                    <td style="height:30px;width:200px;text-align:center">
                        <a class="blue-big-button-gray" id="register-btn">立即注册</a>
                    </td>
                </tr>
            </table>
            <div class="agreement">点击“立即注册”，即表示您同意并愿意遵守
                <a href="foot/agreement.html" target="_blank" style="font-weight: bolder">《用户协议及隐私政策》</a>
            </div>

    </div>
</div>
<div id="footer">
    &copy;2015-2016 Motortravel Intelligence All Rights Reserved
</div>
</body>
<script>
    var countdown=60;
    window.onload=function(){
        $('.send-code-gray').click(function(){
            var code_button=$(this)
            var tel_info = $('#telephone').val();
            var tel_preg = /^1[34578]\d{9}$/;
            if (tel_info == '') {
                layer.msg('请填写您的手机号!');
            } else if (!(tel_preg.test(tel_info))) {
                layer.msg('您的手机号填写有误!');
            }else{
                $.get(url_link+"verfications/"+tel_info,function(data){
                    var obj=JSON.parse(data);
                    if(obj.code!=0){
                        layer.msg('请稍后再发送!');
                    }
                })
            }

        });

        $('#register-btn').click(function(){
            var tel_info = $('#telephone').val();
            var code_info = $('#code').val();
            var pwd_info = $('#password').val();
            var pwd_info_1 = $('#password1').val();
            var tel_preg = /^1[34578]\d{9}$/;
            var psd_preg=/^[a-zA-Z0-9_-]{6,16}$/;
            if (tel_info == '') {
                layer.msg('请填写您的手机号!');
            } else if (!(tel_preg.test(tel_info))) {
                layer.msg('您的手机号填写有误!');
            }else if (code_info=='') {
                layer.msg('请填写您的验证码!');
            }else if (pwd_info=='') {
                layer.msg('请填写您的密码!');
            }else if (pwd_info_1=='') {
                layer.msg('请再次填写您的密码!');
            }else if (!(psd_preg.test(pwd_info))) {
                layer.msg('您的密码格式填写有误!');
            }else if (pwd_info!=pwd_info_1) {
                layer.msg('您两次填写的密码不同!');
            }else{
                $.post(url_link+"users",{
                    mobile:tel_info,
                    vercode:code_info,
                    password:pwd_info
                },function(data){
                    var obj=JSON.parse(data);
                    if(obj.code==0){
                        storage_user_id = obj.data.user_id;
                        storage.setItem("_storage_user_id", storage_user_id);
                        window.location.href="../index.html";
                    }
                })

            }
        });
    };
    function settime(obj) {
        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.value="获取验证码";
            countdown = 60;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.value="重新发送(" + countdown + ")";
            countdown--;
        }
        setTimeout(function(){settime(obj)},1000)
    }
</script>
</html>
